import {defineStore} from "pinia"
import axios from '../utils/request'
export const userStore = defineStore('loginUser',{
    state(){
        return {
            num:1, 
            username:'test',
            token:''
        }
    },
    persist: {//持久化
        enabled: true,
        strategies: [
          {  storage: localStorage, paths:["num","token",'username'] }
        ]
    },
    getters:{
        changeNum:(state)=>{
              return state.num
        }
    }
    ,actions:{
        inc(){  this.num++ },
        setToken(token){  this.token=token },
        setUsername(username){ this.username= username }
        // async login(dataForm){
        //     //登录验证 
        //     axios({
        //         method:'post',
        //         url:'test/login',
        //         data:dataForm
        //     }).then(res=>{
        //         let {code,msg,data} =res.data;
        //         console.log(data.username)  //已经拿到了login后台请求的token的值
        //         this.username =data.username
        //         this.token =data.token 
        //         console.log(this.token) 
        //     })  
        // } 
    }
})

//export default userStore